package com.example.leetdemo.finash;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class Solution539 {

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("00:01");
        list.add("09:08");
        list.add("07:31");
        Solution539 solution539 = new Solution539();
        System.err.println(solution539.findMinDifference(list));
    }

    public int findMinDifference(List<String> timePoints) {
        if (timePoints.size() > 1440) {
            return 0;
        }
        List<Integer> list = timePoints.stream().sorted(String::compareTo).map(this::changeToMinute).collect(Collectors.toList());

        list.add(list.get(0) + 1440);
        int min = Integer.MAX_VALUE;

        for (int i = 1; i < list.size(); i++) {
            min = Math.min(min, list.get(i) - list.get(i - 1));
        }
        return min;
    }

    private int changeToMinute(String t1) {
        String[] time = t1.split(":");
        return Integer.parseInt(time[0]) * 60 + Integer.parseInt(time[1]);
    }

    private String add24Hours(String time) {
        String[] t = time.split(":");
        return (Integer.parseInt(t[0]) + 24) + ":" + t[1];
    }
}
